import React, {lazy, useEffect, useState, Suspense} from 'react';
import {searchById, startProcess} from '@/axios/apis'
import {useSearchParams, useNavigate} from 'react-router-dom';
import {message} from "antd";
import OaTemplate from './OaTemplate.tsx'


const Application = () => {
    // 动态加载组件的高阶组件
    let [searchParams] = useSearchParams()
    const navigate = useNavigate()
    let [processInfo, setProcessInfo] = useState({})
    const [comTemplateName, setComTemplateName] = useState(null)
    useEffect(() => {
        searchById({id: searchParams.get('processId')}).then(res => {
            setProcessInfo(res)
            setComTemplateName(res.templateName)
        })
    }, []);
    const submit = (formData: object) => {
        const params = {
            formData,
            formDataValue: {},
            id: processInfo.id,
            processData: {
                leader: "admin",
            },
            processDefId: processInfo.processDefId,
            processKey: processInfo.processKey,
        }
        if (formData.projectType) {
            params.projectType = formData.projectType;
        }
        console.log('submit', formData)
        startProcess(params).then(res => {
            if (+res.code === 200) {
                message.success('提交成功')
                navigate(-1)
            }
        })
    }
    return (
        <div>
            <OaTemplate oaSubmit={submit} comTemplateName={comTemplateName}/>
        </div>
    );
};

export default Application;